<%@ page language="java" import="java.sql.*" %>
<%	String driver = "org.h2.Driver";
	Class.forName(driver).newInstance();
	Connection con=null;
	ResultSet rst,rst2;
	Statement stmt,stmt2;
	rst=rst2=null;
	stmt=stmt2=null;
	try{
		con=DriverManager.getConnection("jdbc:h2:~/test", "sa", "");
		stmt=con.createStatement();
		stmt2=con.createStatement();
	}
	catch(Exception e){
		System.out.println(e.getMessage());
	}
	rst=stmt.executeQuery("select * from dj");
	rst2=stmt2.executeQuery("select * from audycje");
	
	if(request.getParameter("action") != null){ 
		String id1=request.getParameter("dj");
		String id2=request.getParameter("audycja");
		stmt.executeUpdate("insert into audycja_dj(dj,audycja) values('"+id1+"','"+id2+"')");
	}
		%>
		<html>
		<body>
		<center>
<form action="polacz.jsp" method="post" name="entry" id="entry">
		<select name=dj>
			 	<%
				while(rst.next()){
				%>
				 <option value="<%=rst.getString("id")%>"><%=rst.getString("imie") %> <%=rst.getString("nazwisko") %></option>	  
				<%	}%>
</select>
<select name=audycja>
<%
while(rst2.next()){
%>
 <option value="<%=rst2.getString("id")%>"><%=rst2.getString("nazwa") %></option>
<%}
%>
</select>
<input type="hidden" value="list" name="action">
<input type="submit" value="Polacz">
</form>
			</center>
		</body>
	</html>
<%//rst.close();rst2.close();stmt.close();
	con.close();%>